package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {
@Autowired
    private JedisPool jedisPool;
    public  void clearImg(){
        Jedis resource = jedisPool.getResource();
        Set<String> sdiff = resource.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (sdiff!=null){
            for (String pictureName : sdiff) {
                QiniuUtils.deleteFileFromQiniu(pictureName);
                resource.srem(RedisConstant.SETMEAL_PIC_RESOURCES,pictureName);
            }
        }
        resource.close();
    }
}
